package com.itheima.controller.backend.order;

import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.common.entity.Result;
import com.itheima.common.utils.AliOssUtil;
import com.itheima.pojo.OrderSetting;
import com.itheima.service.OrderSettingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.SetOperations;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;

@RestController
@Api(tags ="预约设置管理")
@Slf4j
@RequestMapping("/ordersetting")
public class OrderSettingController {
    @Autowired
    private OrderSettingService orderService;
    @Autowired
    private AliOssUtil aliOssUtil;
    @Autowired
    private RedisTemplate redisTemplate;

    /*
    * 模板下载
    * */
    @ApiOperation(value = "模板下载")
    @GetMapping("/download")
    public void download(String filename){
        log.info("模板下载");
        orderService.download(filename);
    }

    /*
    * 根据日期修改可预约人数
    * */
    @ApiOperation(value = "根据日期修改可预约人数")
    @PostMapping("/editNumberByOrderDate")
    public Result editNumberByOrderDate(@RequestBody OrderSetting orderSetting){
        log.info("根据日期修改可预约人数");
        orderService.editNumberByOrderDate(orderSetting);
        return new  Result(true,"预约设置成功",null);
    }

    /*
    * 根据年月查询对应的预约设置信息
    * */
    @ApiOperation(value = "根据年月查询对应的预约设置信息")
    @GetMapping("/getOrderSettingByMonth")
    public Result getOrderSettingById(String month){
        log.info("根据年月查询对应的预约设置信息");
        List<OrderSetting> orderSettingList = orderService.getOrderSettingByMonth(month);
        return new Result(true,"查询预约设置信息成功",orderSettingList);
    }

    /*
     * 文件上传
     * */
    @PostMapping("/upload")
    @ApiOperation("文件上传")
    public Result upload(@RequestBody MultipartFile excelFile){
        log.info("文件上传：{}",excelFile);
        orderService.upload(excelFile);
        return new Result(true, MessageConstant.ORDERSETTING_SUCCESS, null);
    }
}
